class ArticlesController < ApplicationController
  before_action :authenticate, except: [:show]
  before_action :set_article, only: [:show, :edit, :update, :destroy, :logs]

  def show
    
  end

  def new
      @article = Article.new
  end

  def edit
      
  end

  def create
    Article.create(article_params)
    redirect_to :root
  end

  def update
    @article.update_attributes(article_params)
    redirect_to :root
  end

  def destroy
    @article.destroy
    redirect_to :root
  end

  def logs 
    @logs = @article.article_logs.order("created_at DESC").page(params[:page]).per(20)
  end

  def restore
    l = ArticleLog.find(params[:lid])
    l.restore
    redirect_to :root
  end  
    
  private
    def set_article
      @article = Article.find(params[:id])
    end
      
    def article_params
      params.require(:article).permit(:title, :content, :user_id)
    end
end
